package com.yunhe.rentcars.pro.controller.car;

import com.yunhe.rentcars.commons.dto.JSONResponse;

import com.yunhe.rentcars.commons.dto.Pageable;
import com.yunhe.rentcars.pro.entity.car.CarSelfuse;
import com.yunhe.rentcars.pro.service.car.CarSelfuseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @author maliang
 * @version V1.0
 * @date 2017/11/23 0023 11:55
 * @Description: 车辆自用控制
 */
@Controller
@RequestMapping("/selfuse")
public class CarSelfuseController {
    @Autowired
    private CarSelfuseService carSelfuseService;

    @RequestMapping
    public String list(){
        return "car/selfuse/list";
    }

    @RequestMapping("/add")
    public String add() {
        return "car/selfuse/add";
    }

    @RequestMapping("/edit")
    public String edit(Long recordId, HttpServletRequest request) {
        CarSelfuse carSelfuse = carSelfuseService.findOne(recordId);
        request.setAttribute("carSelfuse",carSelfuse);
        return "car/selfuse/edit";
    }

    @RequestMapping("/save")
    @ResponseBody
    public JSONResponse save(CarSelfuse carSelfuse){
        carSelfuseService.save(carSelfuse);
        return  JSONResponse.success("创建成功！");
    }

    @RequestMapping("/update")
    @ResponseBody
    public JSONResponse update(CarSelfuse carSelfuse){
        carSelfuseService.update(carSelfuse);
        return JSONResponse.success("修改成功！");
    }

    @RequestMapping("/delBatch")
    @ResponseBody
    public JSONResponse delBatch(String ids){
        carSelfuseService.delBatch(ids);
        return JSONResponse.success("删除成功！");
    }


    @RequestMapping("/listData")
    @ResponseBody
    public Pageable<CarSelfuse> search(CarSelfuse carSelfuse, Integer offset, Integer limit){
        return carSelfuseService.find(carSelfuse,offset,limit);
    }

}
